package com.dongdongshop.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongdongshop.mapper.TbItemMapper;
import com.dongdongshop.pojo.item.TbItem;
import com.dongdongshop.pojo.item.TbItemExample;
import com.dongdongshop.service.ItemServiceI;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
@Service
public class ItemServiceImpl implements ItemServiceI {

    @Resource
    private TbItemMapper tbItemMapper;

    @Override
    public Long selectGoodsById(Long itemId) {
        return tbItemMapper.selectGoodsById(itemId);
    }

    @Override
    public List<TbItem> ListItemsByGoodsId(Long id) {
        TbItemExample example=new TbItemExample();
        TbItemExample.Criteria criteria = example.createCriteria();
        criteria.andGoodsIdEqualTo(id);
        return tbItemMapper.selectByExample(example);
    }

    @Override
    public TbItem selectItemById(Long itemId) {
        return tbItemMapper.selectByPrimaryKey(itemId);
    }

    @Override
    public List<TbItem> selectItemByGoodsId(Long goodsId) {
        TbItemExample example=new TbItemExample();
        TbItemExample.Criteria criteria = example.createCriteria();
        criteria.andGoodsIdEqualTo(goodsId);
        //状态
        criteria.andStatusEqualTo("1");
        // 排序功能 倒叙 根据哪个字段排序 为了设置一进页面规格默认选中哪个
        example.setOrderByClause(" is_default desc");
        return tbItemMapper.selectByExample(example);
    }
}
